import pygame

class ASN(pygame.sprite.Sprite):
    def __init__(self,screen_size):
        pygame.sprite.Sprite.__init__(self)
        self.image = pygame.image.load("1002/100201_01.png").convert_alpha()
        self.width, self.height = screen_size[0], screen_size[1]
        self.roadTop = self.height//2-100
        self.idleimgs = []
        self.idleimgs1 = []
        self.idleimgs1.extend([pygame.image.load("1001/1001_walk_01.png").convert_alpha(),\
                              pygame.image.load("1001/1001_walk_02.png").convert_alpha(),\
                              pygame.image.load("1001/1001_walk_03.png").convert_alpha(),\
                              pygame.image.load("1001/1001_walk_04.png").convert_alpha(),\
                              pygame.image.load("1001/1001_walk_05.png").convert_alpha(),\
                              pygame.image.load("1001/1001_walk_06.png").convert_alpha(),\
                              pygame.image.load("1001/1001_walk_07.png").convert_alpha(),\
                              pygame.image.load("1001/1001_walk_08.png").convert_alpha()])
        self.idleimgs2 = []

        for i in range(8):
            self.idleimgs2.append(pygame.transform.flip(self.idleimgs1[i],True,False))
        #初始状态
        self.idleimgs = self.idleimgs1
        '''
        self.idleimgs.extend([pygame.image.load("1002/1002_idle_01.png").convert_alpha(),\
                              pygame.image.load("1002/1002_idle_02.png").convert_alpha(),\
                              pygame.image.load("1002/1002_idle_03.png").convert_alpha(),\
                              pygame.image.load("1002/1002_idle_04.png").convert_alpha(),\
                              pygame.image.load("1002/1002_idle_05.png").convert_alpha(),\
                              pygame.image.load("1002/1002_idle_06.png").convert_alpha(),\
                              pygame.image.load("1002/1002_idle_07.png").convert_alpha(),\
                              pygame.image.load("1002/1002_idle_08.png").convert_alpha()])
         '''
        self.attackimgs_F = []
        self.attackimgs_F.extend([pygame.image.load("1001/100101_01.png").convert_alpha(),\
                              pygame.image.load("1001/100101_02.png").convert_alpha(),\
                              pygame.image.load("1001/100101_03.png").convert_alpha(),\
                              pygame.image.load("1001/100101_04.png").convert_alpha(),\
                              pygame.image.load("1001/100101_05.png").convert_alpha(),\
                              pygame.image.load("1001/100101_06.png").convert_alpha(),\
                              pygame.image.load("1001/100101_07.png").convert_alpha(),\
                              pygame.image.load("1001/100101_08.png").convert_alpha(),\
                              pygame.image.load("1001/100101_09.png").convert_alpha()])
        self.swordimgs = []
        self.swordimgs.extend([pygame.image.load("1001/100101_projectile_01.png").convert_alpha(),\
                              pygame.image.load("1001/100101_projectile_02.png").convert_alpha(),\
                              pygame.image.load("1001/100101_projectile_03.png").convert_alpha(),\
                              pygame.image.load("1001/100101_projectile_04.png").convert_alpha()])

        self.rect = self.idleimgs[0].get_rect()
        self.rect.left, self.rect.top = 0,self.roadTop
        self.swordrect = self.swordimgs[0].get_rect()
        self.speed = 2
        self.swordSpeed = 2
        self.mask = pygame.mask.from_surface(self.idleimgs[0])
        self.blood = 5

    def moveUp(self):
        if self.rect.top > self.roadTop:
            self.rect.top -= self.speed
        else:
            self.rect.top = self.roadTop
    def moveDown(self):
        if self.rect.bottom < self.height:
            self.rect.bottom += self.speed
        else:
            self.rect.bottom = self.height
    def moveLeft(self):
        self.idleimgs = self.idleimgs2
        if self.rect.left > 0:
            self.rect.left -= self.speed
        else:
            self.rect.left = 0
    def moveRight(self):
        self.idleimgs = self.idleimgs1
        if self.rect.right < self.width:
            self.rect.right += self.speed
        else:
            self.rect.right = self.width

    def swordMove(self):
        self.swordrect.left -= self.swordSpeed



